package com.gxa.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gxa.common.JsonResult;
import com.gxa.pojo.Customer;
import com.gxa.service.CustomerService;
import com.gxa.service.impl.CustomerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/customer_satisfaction/add")
public class CustomerSatisfactionAddServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取表单数据
        int id = Integer.parseInt(request.getParameter("id"));
        String ask_time = request.getParameter("ask_time");
        int quality_satisfaction = Integer.parseInt(request.getParameter("quality_satisfaction"));
        int service_satisfaction = Integer.parseInt(request.getParameter("service_satisfaction"));
        int cost_satisfaction = Integer.parseInt(request.getParameter("cost_satisfaction"));
        int total_satisfaction = Integer.parseInt(request.getParameter("total_satisfaction"));
        String customer_feedback = request.getParameter("customer_feedback");
        //创建customer对象
        Customer customer = new Customer();
        customer.setId(id);
        customer.setAsk_time(ask_time);
        customer.setQuality_satisfaction(quality_satisfaction);
        customer.setService_satisfaction(service_satisfaction);
        customer.setCost_satisfaction(cost_satisfaction);
        customer.setTotal_satisfaction(total_satisfaction);
        customer.setCustomer_feedback(customer_feedback);
        //调用service方法
        CustomerService customerService = new CustomerServiceImpl();
        JsonResult jsonResult = customerService.addCustomerSatisfaction(customer);
        //响应jsonResult
        response.setContentType("application/json; charset=UTF-8");
        response.getWriter().write(JSONObject.toJSONString(jsonResult));
    }
}
